﻿
@model List<DHQGHN.PM2.Models.DHQG.NguoiDungChiTieuModel>
@{

    var lstUser = @Model;
    var danhSachChiTieu = @Model; 
    var columnsMenu = 2;
    var rowsMenu = @Model.Count % 2 == 0 ? (@Model.Count / columnsMenu) : ((@Model.Count + 1) / columnsMenu);

    //var rowsMenu = (int)Math.Round((double)lstUser.Items.Count / (double)columnsMenu + 0.5);
    // int index = 0;

}
@using (
        Html.BeginForm(
        actionName: "ActionSave",
        controllerName: "NguoiDungChiTieu",
        routeValues: new { }, method: FormMethod.Post,
        htmlAttributes: new { @id = "nguoi-dung-chi-tieu-form", @class = "form-inline", @role = "form", @style = "width: 100%;" })
    )
{
    <div class="row">
        <div class="col-md-12">
            <fieldset id="fs1" class="fs_group1" style="border-style:hidden;">
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3" style="">
                        <label style="width: 100px; font-size: 12px;">Năm kế hoạch</label>
                    </div>
                    <div class="col-md-9" style="margin-bottom: 10px;">
                        @Html.DropDownList("NAM_KE_HOACH_ID", ViewBag.NamKeHoach as List<SelectListItem>,
                                        new { @id = "NAM_KE_HOACH_ID", @name = "code", @class = "form-control input-sm", 
                                            @disabled = "disabled",  @placeholder = "" })
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3" style="">
                        <label style="width: 100px; font-size: 12px;">Tài khoản</label>                        
                    </div>
                    <div class="col-md-9" style="margin-bottom: 10px;">
                        @Html.DropDownList("NGUOI_DUNG_ID", ViewBag.NguoiDung as List<SelectListItem>,
                     new
                     {
                         @id = "NGUOI_DUNG_ID",
                         @name = "code",
                         @class = "form-control input-sm",
                                         @disabled = "disabled", @placeholder = "" })
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        <label style="width: 100px; font-size: 12px;">Đơn vị</label>                        
                    </div>
                    <div class="col-md-9">
                        @Html.DropDownList("DON_VI_ID", ViewBag.DonVi as List<SelectListItem>, new { @id = "DON_VI_ID", @class = "form-control input-sm", @disabled = "disabled" })
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-10" style="">
                        <label class="labels" style="">Danh sách chỉ tiêu</label>
                    </div>                    
                </div>

                <div class="row">
                    <div class="col-md-12">
                        <div style="max-height: 200px; overflow: auto; resize: none;">
                            @if (!(danhSachChiTieu.Count == 0 || danhSachChiTieu == null))
                            {
                                <table class="tbl-list" style="margin-left: 15px; width:95%">
                                    @for (int i = 0; i < rowsMenu; i++)
                                    {
                                        <tr>
                                            @for (int j = 0; j < columnsMenu; j++)
                                            {
                                                int index = columnsMenu * i + j;
                                                if (index >= danhSachChiTieu.Count) { break; }
                                                <td style="width: 40%; border:1px solid #DDDDDD;" class="td-onclick">
                                                    <div id="checkboxChiTieuChecked">
                                                        <input style="margin-left: 5px;" type="checkbox" name="@danhSachChiTieu[index].MA_CAP1" />
                                                        <label style="margin-left: 5px;">@danhSachChiTieu[index].TEN_CHI_TIEU</label> 
                                                    </div>
                                                </td>

                                            }
                                        </tr>
                                    }
                                </table>
                            }
                            else
                            {
                                <span class="field-validation-error" style="margin-left:120px"> Chỉ tiêu đã được phân hết. </span>
                            }
                        </div>
                    </div>
                </div>
                
            </fieldset>
        </div>
    </div>  
    
    
    
}


<div id="overlay" class="web_dialog_overlay"></div>
@Scripts.Render("~/bundles/jqueryval")
<script>
        @functions{
            public string GetAntiForgeryToken()
            {
                string cookieToken, formToken;
                AntiForgery.GetTokens(null, out cookieToken, out formToken);
                return cookieToken + "," + formToken;
            }
        }
</script>
<script>
    $('#input-code-app').val(@ViewBag.AppID);
    var $userInRoleForm = $("#user-in-role-form");
    function save() {
        var result = false;
        $("#RoleID").removeAttr("disabled");
        var listID = getListUserInRoleID();

        if ($userInRoleForm.valid() && $('#RoleID').val().trim() > 0) {
            $.ajax({
                contentType: "application/json",
                type: "POST",
                url: $userInRoleForm.attr('action'),
                data: JSON.stringify({ RoleID: $('#RoleID').val().trim(), listID: listID, Descriptions: $('#Descriptions').val() }),
                dataType: 'json',//chú ý là form đặc biệt thì phải điền trường này
                async: false,
                headers: {
                    'VerificationToken': '@GetAntiForgeryToken()'
                },
                success: function (response) {
                    if (response != null && response.status == 200) {
                        window.notice(response.result, window.notice_success);
                        OnCriteria(crrPageIndex);
                        result = true;
                    } else {
                        window.notice(response.result, window.notice_error);
                        //$("#RoleID").attr("disabled", "disabled");
                    }
                }
            });
        }
        return result;
    }

    $('.td-onclick').click(function () {
        $(this).find(':checkbox').click();
    });

    $(":checkbox").click(function (e) {
        e.stopPropagation();
    });

    function getListUserInRoleID() {
        var values = [];
        $('#checkboxUserChecked input:checked').each(function () {
            values.push(this.name);
        });
        return values;
    }
</script>
